<?php if (!defined('BASEPATH'))  exit('No direct script access allowed');


function create_dir($path_name  , $mode = 0777 , $recursive = true )
{
    return mkdir( $path_name , $mode , $recursive);
}
  function delTree($dir) {
      if(!is_dir($dir))
          return false;
        $files = array_diff(scandir($dir), array('.', '..'));
        foreach ($files as $file) {
            (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
        }
        return rmdir($dir);
    }
//bool mkdir ( string  [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

function extract_zip_to( $source , $destination){
    $zip = new ZipArchive;
    if ( $zip->open($source) === TRUE ) {
        $zip->extractTo( $destination );
        $zip->close();
        return true;
    } else {
        return false;
    }
}

 function create_tree($names){
     
        $tree = array();
         sort($names , SORT_STRING );
         foreach ($names as $value)
            {
                $v = explode(' ', $value , 2);
                $num = $v[0];
                $title = $v[1];

            
                $separ_num = explode('.', $num);
                switch ( count($separ_num)) 
                {
                    case 1: 
                        $tree[ $separ_num[0] ] = array($num." " .$title);
                        break;
                    case 2 ;
                        $tree[ $separ_num[0] ][ $separ_num[1] ] = array( $num." " .$title );
                        break;
                    case 3 :$tree[ $separ_num[0] ][ $separ_num[1] ][ $separ_num[2] ] = $num." " .$title;
                        break;
                }            
            }
        
     return $tree;
     
     /*

      * 
      *   
  0 => 
    array (size=1)
      0 => string 'Vue Processus.svg' (length=17)
  1 => 
    array (size=3)
      0 => string 'Gestion de la Supervision.svg' (length=29)
      1 => 
        array (size=3)
          0 => string 'Gestion de la Configuration.svg' (length=31)
          1 => string 'page12.svg' (length=10)
          2 => string 'Page 13.svg' (length=11)
      2 => 
        array (size=1)
          0 => string 'Gestion des Changements.svg' (length=27)
  2 => 
    array (size=4)
      0 => string 'Gestion des Incidents.svg' (length=25)
      1 => 
        array (size=3)
          0 => string 'Gestion des Mises en Production.svg' (length=35)
          1 => string 'Page 14.svg' (length=11)
          2 => string 'page 15.svg' (length=11)
      2 => 
        array (size=1)
          0 => string 'Gestion des Niveaux de Service.svg' (length=34)
      3 => 
        array (size=1)
          0 => string 'Gestion des Finances.svg' (length=24)
  3 => 
    array (size=3)
      0 => string 'Gestion des Probl�mes.svg' (length=25)
      1 => 
        array (size=2)
          0 => string 'Page 10.svg' (length=11)
          1 => string 'Page 16.svg' (length=11)
      2 => 
        array (size=1)
          0 => string 'Page 11.svg' (length=11)
      * 
      */
    
}

function get_list_items($tree)
{
    $data = array();
    for($i = 1 ; $i < count($tree) ; $i++)
    {
        
        $data[] = substr($tree[$i][0] , 0 , strlen($tree[$i][0]) -4 ); // suprission de l'extension .svg
    }
    return $data;
    
}
function create_node($node)
{
    $html = "";
    if(  !isset($node) || !is_array($node))
        return $html;
    
   foreach($node as $elt)
    {
        if(is_array($elt))
        {
           $html .= "<li>" . $elt[0];
           $elt = array_slice($elt, 1);
           $html .= "<ul>" . create_node ($elt) . "</li>\n</ul>\n"; 
        }
            
        else
            $html .= "<li>".$elt."</li>\n";
    }
    
    return $html;
}
function create_navigation_menu($tree)
{
    return "<ul>" .create_node($tree )."</ul>";
    
}
